<script lang="ts" setup>
import { computed, ref, watch } from 'vue'
import { useTransition } from '@vueuse/core'

const props = defineProps({
  title: {
    type: String,
    required: true,
    default: ''
  },
  value: {
    type: Number,
    required: true,
    default: 0
  },
  classSelect: {
    type: Number,
    default: 1
  }
})

const source = ref(0)
let outputValue: any
watch(
  () => props.value,
  (newValue) => {
    outputValue = useTransition(source, {
      duration: 1000
    })
    source.value = newValue
  }
)

// 字体格式
const fontStyle = computed(() => {
  if (props.classSelect == 1) {
    return { color: '#383c4e', fontSize: '30px', fontWeight: 500 }
  } else {
    return { color: '#04c9be', fontSize: '30px', fontWeight: 500 }
  }
})
</script>

<template>
  <el-statistic
    :value="outputValue"
    :value-style="fontStyle"
    :class="{ statistic1: classSelect == 1, statistic2: classSelect == 2 }"
  >
    <template #title
      ><div class="title">{{ title }}</div></template
    >
  </el-statistic>
</template>

<style lang="scss" scoped>
.statistic1 {
  width: 18%;
  height: 90px;
  padding: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
.statistic2 {
  width: 50%;
  margin-top: 10px;
}

.title {
  display: inline-flex;
  align-items: center;
  color: #697086;
  font-size: 14px;
}
</style>
